<link href="../includes/style.css" rel="stylesheet" type="text/css" />     


<title>Order Details Page</title>
 

<?php  

/*

***************************************
*                                     *
* Copyright 2011 David Matthew Pugh   *
* Contact Info:thebravedave@gmail.com *
*                                     *
***************************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
  
require_once "../services/webservices.php";
require_once "index.php";

?>
<html>
<link href="../includes/admin.css " rel="stylesheet" type="text/css" />   
<script type="text/javascript">
    function checkform()
    {
        
        
        go=true;
        if(document.getElementById("note").value=='')
        {
            alert("Please completely fill out event history form.");
            go = false;
            return false;
        }
       
    }
</script> 
<?php
 
  
  
if(isset($_POST['order_history_status']))
{
    $order_history_status = $_POST['order_history_status'];
    $note = $_POST['note'];
    $order_id = $_POST['order_id'];
   
    $orderhistoryObject = new orders_history();
    $orderhistoryObject->order_status = $order_history_status;
    $orderhistoryObject->note = $note;
    $orderhistoryObject->order_id = $order_id;
    $orderhistoryObject->addordershistoryevent();
    
} 
if(isset($_POST['order_id']))
{
  
    
    print "<h2><b>Information About This Order:</b></h2><br /><br />";
    $order_id = $_POST['order_id'];
     
            
    $getRequest = new payment();                
    $getRequest->order_id = $order_id;
    $getResponse = $getRequest->getpaymentbyorderid();

    //Loop through returned XML and display all items        
    $xml = new SimpleXMLElement($getResponse);
    $item_count = $xml->Item_Count;   
    if($item_count != 0)   //get payment information and format/print it        
    {   
       
        echo '<big><b>Payment Information</b></big><br />';
         echo '<div class="smallcorerightmargin">';     
        foreach ($xml->Item as $eachitem) 
        {   
            $order_id = $eachitem->order_id; 
            $payment_type = $eachitem->payment_type;
            $payment_amount = (double)$eachitem->amount;
            $payment_amount = number_format($payment_amount, 2, '.', '');   
            $order_status = $eachitem->order_status;  
            $payment_total = $eachitem->amount;                  
            $ipaddress = $eachitem->ip_address;
            $payment_date = $eachitem->payment_date;                     
            $first_name = $eachitem->first_name;                       
            $last_name = $eachitem->last_name;                    
            $email = $eachitem->email;
                    
            if($payment_type == "paypal")
            {
                $payment_type = "Paypal";
                $paymentObject = new payment();
                $paymentObject->order_id = $order_id;
                $paypalpaymentReturn = $paymentObject->getpaypalpaymentbyorderid();
                $paypalpaymentXml = new SimpleXMLElement($paypalpaymentReturn);
                foreach($paypalpaymentXml->Item as $paypalpaymentItem)
                {
                    $correlation_id = $paypalpaymentItem->correlation_id;
                    $payer_id = $paypalpaymentItem->payer_id;                            
                }
?>              <b>Payment Type:</b> <?php echo $payment_type; ?><br />
                <b>Order_ID:</b> <?php echo $order_id; ?><br />      
                <b>Payment Date:</b> <?php echo $payment_date ?><br />
                <b>Payment Amount:</b> <?php echo "$" . $payment_amount; ?><br />      
                <b>Order Status:</b> <?php echo $order_status?><br />                       
                <b>Transaction ID:</b> <?php echo $correlation_id?><br />  
                <b>First Name:</b> <?php echo $first_name;?><br />                       
                <b>Last Name:</b> <?php echo $last_name;?><br />                       
                <b>Paypal Payer ID:</b> <?php echo $payer_id;?><br />                              
                <b>Email :</b> <?php echo $email;?><br />    
                <br /> 
             
<?php
            } 
            else  //else it was payment by credit card
            {
                $payment_type = "Credit Card";
                $paymentObject = new payment();
                $paymentObject->order_id = $order_id;
                $creditcardpaymentReturn = $paymentObject->getcreditcardpaymentbyorderid();
                $creditcardpaymentXml = new SimpleXMLElement($creditcardpaymentReturn);
                foreach($creditcardpaymentXml->Item as $creditcardpaymentItem)
                {
                    $correlation_id = $creditcardpaymentItem->correlation_id;
                    $lastfourdigits = $creditcardpaymentItem->lastfourdigits;
                    $street_address = $creditcardpaymentItem->street_address;
                    $city = $creditcardpaymentItem->city;
                    $state = $creditcardpaymentItem->state;
                    $zip_code = $creditcardpaymentItem->zip_code;                            
                } 
?>              <b>Payment Type:</b> <?php echo $payment_type; ?><br />
                <b>Order_ID:</b> <?php echo $order_id; ?><br />      
                <b>Payment Date:</b> <?php echo $payment_date ?><br />
                <b>Payment Amount:</b> <?php echo "$" . $payment_amount; ?><br />      
                <b>Order Status:</b> <?php echo $order_status?><br />                      
                <b>Transaction ID:</b> <?php echo $correlation_id?><br /> 
                <b>Last Four Digits On Card:</b> <?php echo $lastfourdigits?><br />    
                <b>First Name:</b> <?php echo $first_name;?><br />                       
                <b>Last Name:</b> <?php echo $last_name;?><br />
                <b>Street Address:</b> <?php echo $street_address;?><br />
                <b>City:</b> <?php echo $city;?><br />    
                <b>State:</b> <?php echo $state;?><br />       
                <b>Zip Code:</b> <?php echo $zip_code;?><br />
                <b>Email :</b> <?php echo $email;?><br />    
                <br /> 

<?php       
            } 
            if($order_status != "refunded")
            {     
?>
                <form action="./updateorderdetails.php" method="POST">
                <input type="hidden" name="order_id" value="<?php echo $order_id; ?>" />
                <input type="hidden" name="order_status" value="<?php echo $order_status; ?>"/>
                <input type="submit" name="submit" value="update order status" />
                                
                </form>
<?php
            }
            echo '</div>';
                    

        }
    } 
       
    $getRequest = new orders();                
    $getRequest->order_id = $order_id;
    $getResponse = $getRequest->getorderbyorderid();

    //Loop through returned XML and display all items        
    $xml = new SimpleXMLElement($getResponse);
    $item_count = $xml->Item_Count;                  
    if($item_count > 0)
    {
              
           
        print "<big><b>Items In Order</b></big>";
        echo '<div class="smallcorerightmargin">';      
        $total = 0.0;   
        $items_id_name_array = array(); 
        foreach ($xml->Item as $eachitem3)         
        {       
            $order_id = $eachitem3->order_id;  
            $gw_id = (int)$eachitem3->gw_id;                 
            $sw_id = (string)$eachitem3->sw_id;
            $name = $eachitem3->name;                 
            $qty = $eachitem3->qty;        
            $price = (double)$eachitem3->price;             
            $subtotal = $price * $qty; 
            $total = $total + $subtotal;
                    
            //get all info for a href link structure to item's page
            $getrequest2 = new item();
            $getrequest2->gw_id = $gw_id;
            $getresponse2 = $getrequest2->getitembyid();
            $xml = new SimpleXMLElement($getresponse2);
            foreach($xml->Item as $eachitem2)
            {
                $category_id = $eachitem2->category_id;
                           
            }
            $getrequest3 = new itemcategory();
            $getrequest3->category_id = $category_id;
            $getresponse3 = $getrequest3->getcategorybycategoryid();                    
            $xml3 = new SimpleXMLElement($getresponse3);
            foreach($xml3->Item as $eachitem3)
            {
                $category = $eachitem3->category;
                $parent_category_id = $eachitem3->parent_category_id;
                $parent_category_id = (int)$parent_category_id;
                        
            }
                  
                       
            $getrequest4 = new itemcategory();
            $getrequest4->category_id = $parent_category_id;
            $getresponse4 = $getrequest3->getcategorybycategoryid();
            $xml4 = new SimpleXMLElement($getresponse4);
            foreach($xml4->Item as $eachitem4)
            {
                $parent_category = $eachitem4->category;   
            }
                   
                    
?>
            <br /><b>Item Name:</b>
<?php                     
            if($sw_id != "")
            {                     
                $namedetails = $name->xml->name;                  
                $sw_name = $namedetails->sw_name; 
                $gw_name = $namedetails->gw_name;                    
                $descriptor_items = $namedetails->descriptor_item;
                $num_desc_items = count($descriptor_items);                
                $temp_num = 0;
                $string = $gw_name . "[";                 
                while($temp_num != $num_desc_items)
                {                     
                    $is_category_array = $descriptor_items->$temp_num;
                    $is_category = $is_category_array->category;
                    $is_descriptor = $is_category_array->descriptor;
                    $temp_num++;
                    $string .= $is_category . ":" . $is_descriptor . ", ";
                }
                $string = rtrim($string, ", ") . "]"; 
                $items_id_name_array[$sw_id] = $string; 
                echo '<a href="./updateitem.php?gw_id=' . $gw_id . '&Edit_Button=Edit_Button">' . $string . '</a><br /> '; 
                echo '<b>Item ID: </b>' . $sw_id . '<br />';              
            }
            else
            {
                $items_id_name_array[$gw_id] = (string)$name;
                $string = $name;
                echo '<a href="./updateitem.php?gw_id=' . $gw_id . '&Edit_Button=Edit_Button">' . $string . '</a><br /> ';
                echo '<b>Item ID: </b>' . $gw_id . '<br />';            
            }                    
?>
                   
            <b>Quantity:</b> <?php echo $qty;?><br />
            <b>Price:</b> $<?php echo $price;?><br />
<?php
                 
            echo "<b>Subtotal:</b>$" . number_format($subtotal, 2, '.', '') . '<br />';
            
        } 
        
        echo "<b>Total For Items:</b>$" . number_format($total, 2, '.', '');        
        echo '</div>';
      
            $shipping = new shipping();                
            $shipping->order_id = $order_id;
            $shippingResponse = $shipping->getshippingbyorderid();           
            $xml = new SimpleXMLElement($shippingResponse);
            $item_count = $xml->Item_Count;
      
    }
    if($item_count > 0)
    {
                    
   
        print "<br /><b><big>Shipping Information</big></b><br />";
        echo '<div class="smallcorerightmargin">';        
        foreach ($xml->Item as $eachitem)         
        {
            $order_id = $eachitem->order_id;  
            $first_name = $eachitem->first_name;
            $last_name = $eachitem->last_name; 
            $street_address = $eachitem->street_address;           
            $city = $eachitem->city;
            $state = $eachitem->state;
            $zip_code = $eachitem->zip_code;    
            $service = $eachitem->service;
            $carrier = $eachitem->carrier; 
            $shipping_total = (double)$eachitem->shipping_total;
            $completed_order = $eachitem->completed_order;                      
         
?>           
                        
                        
            <b>First Name:</b> <?php echo $first_name;?><br />    
            <b>Last Name:</b> <?php echo $last_name;?><br />
            <b>Street Address:</b> <?php echo $street_address;?><br />  
            <b>City:</b> <?php echo $city;?><br />  
            <b>State:</b> <?php echo $state;?><br />
            <b>Zip Code:</b> <?php echo $zip_code;?><br />
            <b>Shipping Service:</b> <?php echo $carrier . ":" . $service;?><br /> 
            <b>Shipping Total:</b><?php echo "$" . $shipping_total;?><br />                           
<?php                    
          }  
          echo '</div>';            
    }

    $orderObject = new orders();
    $orderObject->order_id = $order_id;
    $orderResponse = $orderObject->getorderboxesbyorderid();
    $orderXml = new SimpleXMLElement($orderResponse);
               
   
    echo '<br /><br /><b><big>Packaging For Shipping</big></b><br />';
     echo '<div class="smallcorerightmargin">';                    
    foreach($orderXml->Item as $orderItem)
    {   
        $order_box_id = $orderItem->id;
        $status = $orderItem->status;
        $mailstatus = $orderItem->mail;
        $tracking_number = $orderItem->tracking_number;
        $orderObject->order_box_id = $order_box_id;
        $orderitemsResponse = $orderObject->getorderboxitemsbyboxid();                       
        $orderitemsXml = new SimpleXMLElement($orderitemsResponse);
        echo '<b>Box #' . $order_box_id . '</b><br />';
        echo '<b>Status:</b>' . $status . '<br/>';
        echo '<b>Mail Status: </b>' . $mailstatus . '<br />';
        echo '<b>Tracking #</b>' . $tracking_number . '<br /><br />';
        $tmpnum = 1;
        foreach($orderitemsXml->Item as $orderitemsItem)
        {
            $orderitem_id = $orderitemsItem->id;
            $orderitem_item_id = $orderitemsItem->item_id;
                   
            if(strpos($orderitem_item_id, "SWIDGET") == false)  //then its a general widget
            {                           
                echo '<b>Item #</b> ' . $tmpnum . '</b><br />';
                echo '<b>Item ID:</b>' . $orderitem_item_id . '<br />';
                echo '<b>Item Name:</b>' . $items_id_name_array[(int)$orderitem_item_id] . '<br /><br />';                 
            }
            else  //then it's a specific widget     
            {
                echo '<b>Item #' . $tmpnum . '</b><br />';
                echo '<b>Item ID:</b>' . $orderitem_item_id . '<br />';
                echo '<b>Name:</b>' . $items_id_name_array[(string)$orderitem_item_id] . '<br /><br />';                
                
            }
            $tmpnum++;               
        }                                    
    }
?>  
                         
    <form action="./updateorderdetails.php" method="POST">
    <input type="hidden" name="email" value="<?php echo $email; ?>" />
    <input type="hidden" name="order_id" value="<?php echo $order_id; ?>" />
    <input type="hidden" name="updatepackaging" value="updatepackaging" />
    <input type="submit" name="submit" value="Update Packaging" />                  
    </form>  
    </div>  
    <br /><br />
             
<?php
         
    $getRequest = new orders_history();    
    $getRequest->order_id = $order_id; 
    $getResponse = $getRequest->getordershistorybyorderid();

    //Loop through returned XML and display all items        
    $xml = new SimpleXMLElement($getResponse);

    $item_count = $xml->Item_Count;
      
        
    if($item_count != 0)
    {  
        echo '<b><big>Order History</big></b><br />'; 
         echo '<div class="smallcorerightmargin">';                
        foreach ($xml->Item as $eachitem)         
        {     
            $order_event_date = $eachitem->order_event_date; 
            $order_status  = $eachitem->order_status;
            $note = $eachitem->note;                                         
 ?>
  
            <b>Order Event Date:</b> <?php echo $order_event_date?><br />  
            <b>Category:</b> <?php echo $order_status;?><br />
            <b>note:</b> <?php echo $note;?><br />   
            <br /> 
 <?php
                     
                             
         }  
         echo '</div>';   

     }                       
   
?>  
    
      
        
     <b><big>Insert New Order History Information</big></b><br /> 
     <div class="smallcorerightmargin">     
     <form action="./orderdetails.php" method="POST" name="order_history">   

        <input type="hidden" name="order_id" id="order_id" value="<?php echo $order_id?>">
       
        Order Event Category:<br />
        <select name="order_history_status">
        <option value="General Info">General Info</option> 
        <option value="Shipping">Shipping</option>
        <option value="Complete">Complete</option>
        <option value="Returned">Returned</option>
        
        
        </select>
        <br />
        Notes About Event:<br />
        <input type="text" id="note" name="note">
        <br />
        <input type="submit" id="submit" value="submit history event" onclick="javascript: return checkform();"> 
        </form>
        </div>
     <?php
        
        }
 
?>
</html>